#!/bin/sh

INSTALL_DIR="/usr/local/${PACKAGE}"
ZT_HOMEDIR="/var/lib/zerotier-one"
LOG_FILE="/var/log/zerotier-one.log"

echo "$(date) UNINSTALL: killing zerotier-one and watchdog" >> ${LOG_FILE} ;
killall zerotier-one ;
pkill -f "zerotier-watchdog" ;
echo "$(date) UNINSTALL: removing config files but leaving identity.* files" >> ${LOG_FILE} ;
# remove all files except for identity files and network config files (for future convenience)
find ${ZT_HOMEDIR} -type f ! -name 'identity.*' -delete
rm -rf ${INSTALL_DIR} ${ZT_HOMEDIR}/peers.d ${ZT_HOMEDIR}/controller.d ${ZT_HOMEDIR}/iddb.d /usr/local/bin/zerotier-cli /usr/local/bin/zerotier-idtool
# nginx de-config
echo "$(date) UNINSTALL: removing nginx reverse proxy config" >> ${LOG_FILE} ;
rm -f /usr/local/etc/nginx/conf.d/dsm.zerotier.conf
rm -f /etc/init.d/zerotier
# TODO: check devicemap and remove all ls /etc/sysconfig/network-scripts entries

exit 0
